<%@ Page Language="C#" Inherits="CuteEditor.Dialogs.FileBrowserPage" %>
<HTML>
	<HEAD>
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<meta http-equiv="Page-Enter" content="blendTrans(Duration=0.1)">
		<meta http-equiv="Page-Exit" content="blendTrans(Duration=0.1)">
		<META Http-Equiv="Cache-Control" Content="no-cache">
		<META Http-Equiv="Pragma" Content="no-cache">
		<META HTTP-EQUIV="EXPIRES" CONTENT="0">
		<link rel="stylesheet" href='style.css'>
		<script src=dialog.js></script><script src=../_shared.js></script>
		<script src="filebrowserpage.js"></script>
		<script src="sorttable.js"></script>
		<script language="JavaScript">
		var OxOee9b=["disabled","srcElement","[[Disabled]]","[[SpecifyNewFolderName]]","","value","hiddenActionData","[[CopyMoveto]]","/","[[AreyouSureDelete]]","parentNode","isdir","text","hiddenAction","rename","path","True","False",":","cancelBubble","backgroundColor","style","#eeeeee","tagName","INPUT","changedir","hiddenFile","url","TargetUrl"]; function CreateDir_click(){if(event[OxOee9b[0x1]][OxOee9b[0x0]]){ alert(OxOee9b[0x2]) ;return false;} ;var Ox2f4=prompt(OxOee9b[0x3],OxOee9b[0x4]);if(Ox2f4){ document.getElementById(OxOee9b[0x6])[OxOee9b[0x5]]=Ox2f4 ;return true;} else {return false;} ;}  ; function Move_click(){if(event[OxOee9b[0x1]][OxOee9b[0x0]]){ alert(OxOee9b[0x2]) ;return false;} ;var Ox2f4=prompt(OxOee9b[0x7],OxOee9b[0x8]);if(Ox2f4){ document.getElementById(OxOee9b[0x6])[OxOee9b[0x5]]=Ox2f4 ;return true;} else {return false;} ;}  ; function Copy_click(){if(event[OxOee9b[0x1]][OxOee9b[0x0]]){ alert(OxOee9b[0x2]) ;return false;} ;var Ox2f4=prompt(OxOee9b[0x7],OxOee9b[0x8]);if(Ox2f4){ document.getElementById(OxOee9b[0x6])[OxOee9b[0x5]]=Ox2f4 ;return true;} else {return false;} ;}  ; function Delete_click(){if(event[OxOee9b[0x1]][OxOee9b[0x0]]){ alert(OxOee9b[0x2]) ;return false;} ;return confirm(OxOee9b[0x9]);}  ; function EditImg_click(Oxba){if(Oxba[OxOee9b[0x0]]){ alert(OxOee9b[0x2]) ;return false;} ; row=Oxba[OxOee9b[0xa]][OxOee9b[0xa]] ;var name;if(row[OxOee9b[0xb]]){ name=prompt(OxOee9b[0x3],row.text) ;} else { name=prompt(OxOee9b[0x3],row.text) ;} ;if(name&&name!=row[OxOee9b[0xc]]){ document.getElementById(OxOee9b[0xd])[OxOee9b[0x5]]=OxOee9b[0xe] ; document.getElementById(OxOee9b[0x6])[OxOee9b[0x5]]=(row[OxOee9b[0xb]]?OxOee9b[0x10]:OxOee9b[0x11])+OxOee9b[0x12]+row[OxOee9b[0xf]]+OxOee9b[0x12]+name ; postback() ;} ; event[OxOee9b[0x13]]=true ;}  ; function row_over(Oxc4){ Oxc4[OxOee9b[0x15]][OxOee9b[0x14]]=OxOee9b[0x16] ;}  ; function row_out(Oxc4){ Oxc4[OxOee9b[0x15]][OxOee9b[0x14]]=OxOee9b[0x4] ;}  ; function row_click(Oxc4){if(Oxc4[OxOee9b[0xb]]){if(event[OxOee9b[0x1]][OxOee9b[0x17]]==OxOee9b[0x18]){return ;} ; document.getElementById(OxOee9b[0xd])[OxOee9b[0x5]]=OxOee9b[0x19] ; document.getElementById(OxOee9b[0x6])[OxOee9b[0x5]]=Oxc4.getAttribute(OxOee9b[0xf]) ; postback() ;} else { document.getElementById(OxOee9b[0x1a])[OxOee9b[0x5]]=Oxc4.getAttribute(OxOee9b[0xf]) ; document.getElementById(OxOee9b[0x1c])[OxOee9b[0x5]]=Oxc4.getAttribute(OxOee9b[0x1b]) ; Actualsize() ;} ;}  ; function postback(){ <%=Page.GetPostBackEventReference(hiddenAction,"")%> ;}  ;
		</script>
		<style>
		.row { HEIGHT: 22px }
		.cb { VERTICAL-ALIGN: middle }
		.itemimg { VERTICAL-ALIGN: middle }
		.editimg { VERTICAL-ALIGN: middle }
		.cell1 { VERTICAL-ALIGN: middle }
		.cell2 { VERTICAL-ALIGN: middle }
		.cell3 { PADDING-RIGHT: 4px; VERTICAL-ALIGN: middle; TEXT-ALIGN: right }
		.cb { }
		</style>
	</HEAD>
	<body bottomMargin="0" topMargin="10" marginwidth="0" marginheight="0">
		<form runat="server" enctype="multipart/form-data" id="Form1">
			<!-- start hidden -->
			<script>
        var OxOb9e3=["onload","value","hiddenAlert","","hiddenAction","hiddenActionData"]; window[OxOb9e3[0x0]]=reset_hiddens ; function reset_hiddens(){if(document.getElementById(OxOb9e3[0x2])[OxOb9e3[0x1]]){ alert(document.getElementById(OxOb9e3[0x2]).value) ;} ; document.getElementById(OxOb9e3[0x2])[OxOb9e3[0x1]]=OxOb9e3[0x3] ; document.getElementById(OxOb9e3[0x4])[OxOb9e3[0x1]]=OxOb9e3[0x3] ; document.getElementById(OxOb9e3[0x5])[OxOb9e3[0x1]]=OxOb9e3[0x3] ;}  ;
			</script>
			<input type="hidden" runat="server" id="hiddenDirectory" NAME="hiddenDirectory"> <input type="hidden" runat="server" id="hiddenFile" NAME="hiddenFile">
			<input type="hidden" runat="server" enableviewstate="false" id="hiddenAlert" NAME="hiddenAlert"> <input type="hidden" runat="server" enableviewstate="false" id="hiddenAction" onserverchange="hiddenAction_ServerChange" NAME="hiddenAction">
			<input type="hidden" runat="server" enableviewstate="false" id="hiddenActionData" NAME="hiddenActionData">
			<!-- end hidden -->
			<table border="0" cellspacing="2" cellpadding="0" width="100%" align="center">
				<tr>
					<td width="20">
						<asp:Image ID="Image1" Runat="server" ImageUrl="../images/openfolder.gif"></asp:Image>
					</td>
					<td width="240" class="normal">
						<asp:Label Runat="server" ID="FolderDescription"></asp:Label>
					</td>
					<td>
						<asp:ImageButton ID="CreateDir" Runat="server" AlternateText="[[Createdirectory]]" ImageUrl="../images/newfolder.gif"
							onMouseOver="CuteEditor_ColorPicker_ButtonOver(this);" Visible="true"
							OnClick="CreateDir_Click" />
						<asp:ImageButton ID="Copy" Runat="server" AlternateText="[[Copyfiles]]" ImageUrl="../images/Copy.gif"
							onMouseOver="CuteEditor_ColorPicker_ButtonOver(this);" Visible="true"
							OnClick="Copy_Click" />
						<asp:ImageButton ID="Move" Runat="server" AlternateText="[[Movefiles]]" ImageUrl="../images/move.gif"
							onMouseOver="CuteEditor_ColorPicker_ButtonOver(this);" Visible="true"
							OnClick="Move_Click" />
						<IMG src="../images/zoom_in.gif" onclick="Zoom_In();" Alt="[[ZoomIn]]" class="dialogButton"
							onmouseover="CuteEditor_ColorPicker_ButtonOver(this);"> <IMG src="../images/zoom_out.gif" onclick="Zoom_Out();" Alt="[[ZoomOut]]" class="dialogButton"
							onmouseover="CuteEditor_ColorPicker_ButtonOver(this);"> <IMG src="../images/bestfit.gif" onclick="BestFit();" Alt="[[BestFit]]" class="dialogButton"
							onmouseover="CuteEditor_ColorPicker_ButtonOver(this);"> <IMG src="../images/Actualsize.gif" onclick="Actualsize();" Alt="[[ActualSize]]" class="dialogButton"
							onmouseover="CuteEditor_ColorPicker_ButtonOver(this);"> 
							<% if(secset.AllowModify) {%>
							<IMG  class="dialogButton" onmouseover="CuteEditor_ColorPicker_ButtonOver(this);" src="../images/imageeditor.gif" onclick="ImageEditor();" Alt="[[ImageEditor]]">
							<%
							}
							else
							{
							%>
								<IMG  class="CuteEditorButtonDisabled" onmouseover="CuteEditor_ColorPicker_ButtonOver(this);" src="../images/imageeditor.gif" Alt="[[ImageEditor]]">
							<%
							}
							%>
					</td>
				</tr>
			</table>
			<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
				<tr>
					<td valign="top" nowrap width="270">
						<div style="BORDER: 1.5pt inset;  VERTICAL-ALIGN: middle; OVERFLOW: auto; WIDTH: 270; HEIGHT: 250px; Padding: 0 0 0 0; BACKGROUND-COLOR: white">
							<asp:Table ID="FoldersAndFiles" Runat="server" CellSpacing="1" CellPadding="1" Width="100%" CssClass="sortable">
								<asp:TableRow BackColor="#f0f0f0">
									<asp:TableHeaderCell Width="16px" >
						<asp:ImageButton ID="Delete" Runat="server" AlternateText="[[Deletefiles]]"
							onMouseOver="CuteEditor_ColorPicker_ButtonOver(this);" ImageUrl="../images/s_cut.gif"
							Visible="true" OnClick="Delete_Click" />
									</asp:TableHeaderCell>
									<asp:TableHeaderCell Width="16px" >
						<asp:ImageButton ID="DoRefresh" Runat="server" AlternateText="[[Refresh]]" ImageUrl="../images/s_refresh.gif"
							onMouseOver="CuteEditor_ColorPicker_ButtonOver(this);" Visible="true"
							OnClick="DoRefresh_Click" />
									</asp:TableHeaderCell>
									<asp:TableHeaderCell ID="name_Cell" Wrap=True Width="146px" CssClass="filelistHeadCol">[[Name]]</asp:TableHeaderCell>
									<asp:TableHeaderCell ID="size_Cell" Width="62px" CssClass="filelistHeadCol">[[Count]]/[[Size]]</asp:TableHeaderCell>
									<asp:TableHeaderCell ID="op_Cell"  Width="16px">&nbsp;</asp:TableHeaderCell>
								</asp:TableRow>
							</asp:Table>
						</div>
					</td>
					<td width="10">&nbsp;
					</td>
					<td valign="top">
						<div style="border:1.5pt inset; Padding: 0 0 0 0; vertical-align: top; overflow: auto; WIDTH: 340px; HEIGHT: 250px; BACKGROUND-COLOR: white;">
							<div id="divpreview" style="BACKGROUND-COLOR: white" height="100%" width="340px">
								<img id="img_demo" src="../images/1x1.gif">
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="3" height=5>
					</td>
				</tr>
			</table>
			<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">			
				<tr>
					<td valign="top">
						<fieldset>
							<legend>
								[[Layout]]</legend>
							<table border="0" cellpadding="4" cellspacing="0" width="220">
								<tr>
									<td>
										<table border="0" cellpadding="1" cellspacing="0" class="normal">
											<tr>
												<td width="100">[[Alignment]]:</td>
												<td>
													<select NAME="ImgAlign" style="WIDTH : 80px" ID="Align" onchange="do_preview()" onpropertychange="do_preview()">
														<OPTION id="optNotSet" value="">[[Notset]]</OPTION>
														<OPTION id="optLeft" value="left">[[Left]]</OPTION>
														<OPTION id="optRight" value="right">[[Right]]</OPTION>
														<OPTION id="optTexttop" value="textTop">[[Texttop]]</OPTION>
														<OPTION id="optAbsMiddle" value="absMiddle">[[Absmiddle]]</OPTION>
														<OPTION id="optBaseline" value="baseline" selected>[[Baseline]]</OPTION>
														<OPTION id="optAbsBottom" value="absBottom">[[Absbottom]]</OPTION>
														<OPTION id="optBottom" value="bottom">[[Bottom]]</OPTION>
														<OPTION id="optMiddle" value="middle">[[Middle]]</OPTION>
														<OPTION id="optTop" value="top">[[Top]]</OPTION>
													</select>
												</td>
											</tr>
											<tr>
												<td nowrap>[[Bordersize]]:</td>
												<td>
													<INPUT TYPE="text" SIZE="2" NAME="Border" onchange="do_preview()" onpropertychange="do_preview()"
														onkeyup="event.returnValue=IsDigit();" style="WIDTH : 80px" ID="Border">
												</td>
											</tr>
											<tr>
												<td nowrap>[[Bordercolor]]:</td>
												<td>
													<input type="text" id="bordercolor" name="bordercolor" size="7" style="WIDTH:57px">
													<img src="../images/colorpicker.gif" id="bordercolor_Preview" align="absMiddle" style='BEHAVIOR:url(../ColorPicker.htc.aspx?culture=[[_culture_]]&[[DNN_Arg]])'
														oncolorchange="bordercolor.value=this.selectedColor; bordercolor.style.backgroundColor=this.selectedColor">
												</td>
											</tr>
											<tr>
												<td colspan="2">
													<table border="0" cellpadding="0" cellspacing="0" class="normal">
														<tr>
															<td width="100" nowrap>[[Width]]:</td>
															<td>
																<INPUT TYPE="text" SIZE="2" id="inp_width" onkeyup="checkConstrains('width');" ONKEYPRESS="event.returnValue=IsDigit();" style="WIDTH : 80px">
															</td>
															<td rowspan="2" align="right" valign="middle"><img src="../images/locked.gif" id="imgLock" width="25" height="32" alt="Constrained Proportions" /></td>
														</tr>
														<tr>
															<td nowrap>[[Height]]:</td>
															<td>
																<INPUT TYPE="text" SIZE="2" id="inp_height" onkeyup="checkConstrains('height');" ONKEYPRESS="event.returnValue=IsDigit();" style="WIDTH : 80px">
															</td>
														</tr>
														<tr>
															<td colspan="2">
																<input type="checkbox" id="constrain_prop" checked onclick="javascript:toggleConstrains();" />
																Constrain Proportions</td>
														</tr>
													</table>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</fieldset>
						<fieldset>
						<legend>[[Spacing]]</legend>
							<table border="0" cellpadding="4" cellspacing="0">
								<tr>
									<td>
										<table border="0" cellpadding="1" cellspacing="0" class="normal">
											<tr>
												<td valign="middle" width="100">[[Horizontal]]:</td>
												<td><INPUT TYPE="text" SIZE="2" NAME="HSpace" value="5" onchange="do_preview()" onpropertychange="do_preview()"
														ONKEYPRESS="event.returnValue=IsDigit();" style="WIDTH:80px" ID="HSpace">
												</td>
											</tr>
											<tr>
												<td valign="middle">[[Vertical]]:</td>
												<td><INPUT TYPE="text" SIZE="2" NAME="VSpace" onchange="do_preview()" onpropertychange="do_preview()"
														ONKEYPRESS="event.returnValue=IsDigit();" style="WIDTH:80px" ID="VSpace"></td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</fieldset>
					</td>
					<td width="10">
					</td>
					<td valign="top">
						<fieldset>
							<legend>
								[[Insert]]</legend>
							<table border="0" cellpadding="4" cellspacing="0">
								<tr>
									<td>
										<table border="0" cellpadding="1" cellspacing="0" class="normal">
											<tr>
												<td valign="middle">
													URL:</td>
												<td>
													<input type="text" id="TargetUrl" onpropertychange="do_preview()" size="40" name="TargetUrl"
														runat="server"></td>
											</tr>
											<tr>
												<td valign="middle">[[Alternate]]:</td>
												<td valign="middle"><input type="text" id="AlternateText" size="40" NAME="AlternateText"></td>
											</tr>
											<tr>
												<td valign="middle" nowrap>[[longDesc]]:</td>
												<td valign="middle"><input type="text" id="longDesc" size="40" NAME="longDesc"><img src="../images/Accessibility.gif" align="absMiddle" hspace="5"></td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</fieldset>
						<fieldset align="center" id="fieldsetUpload">
							<legend>
								[[Upload]] (Max file size allowed
								<%= CuteEditor.Impl.FileStorage.FormatSize(secset.MaxImageSize * 1024)%>
								)</legend>
							<table border="0" cellspacing="2" cellpadding="0" width="100%" class="normal" align="center">
								<tr>
									<td valign="top" style="FONT-SIZE: 8pt; VERTICAL-ALIGN: middle; FONT-FAMILY: MS Sans Serif">
										<asp:Label ID="Label_PictureUpload" Runat="server"></asp:Label>
										<input id="InputFile" size="45" type="file" runat="server" style="HEIGHT:20px" NAME="InputFile">&nbsp; <br>
										<asp:Button ID="uploadButton" Text="[[Upload]]" Runat="server" OnClick="uploadButton_Click" />&nbsp;
									</td>
								</tr>
								<tr>
									<td height="5">
									</td>
								</tr>
								<tr>
									<td>
										<% if(secset.RestrictUploadedImageDimension) {%>
										<li>
											Max image dimension is
											<%= secset.MaxImageWidth%>
											x
											<%= secset.MaxImageHeight%>
											pixels.
										</li>
										<li>
											Auto resize uploaded images function is
											<%= secset.AutoResizeUploadedImages? "on":"off" %>
											.</li>
										<%}%>
										<li>
											<nobr>
											Max Upload folder size is : <%= CuteEditor.Impl.FileStorage.FormatSize(secset.MaxImageFolderSize * 1024)%>.
											Used: <%= CuteEditor.Impl.FileStorage.FormatSize(fs.GetDirectorySize(fs.VirtualRoot)) %>
											<span style="background-color:green;height:3px;width:40px;font-size:3px">
												<span style="background-color:red;height:3px;width:<%= GetUsedSpaceBarWidth() %>px;font-size:3px"></span>
											</span>
											</nobr>
										</li>
									</td>
								</tr>
							</table>
						</fieldset>
						<div align="center" style="padding-top:4px;">
							<input class="inputbuttoninsert" type="button" value="[[Insert]]" onclick="do_insert()"
								id="Button1">&nbsp;&nbsp;&nbsp; <input class="inputbuttoncancel" type="button" value="[[Cancel]]" onclick="do_cancel()"
								id="Button2">
						</div>
					</td>
				</tr>
			</table>
		</form>
		<script runat="server">
			protected override void InitOfType()
			{
				this.Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);	
				fs.VirtualRoot=CuteEditor.EditorUtility.ProcessWebPath(Context,null,secset.ImageGalleryPath).TrimEnd('/')+"/";
			}
			protected override void GetFiles(ArrayList files)
			{
				foreach (string ext in secset.ImageFilters)
				{
					if (ext == null || ext.Length == 0) continue;

					files.AddRange(fs.GetFileItems(CurrentDirectory, "*" + ext));
				}
			}
			protected override bool AllowFileName(string filename)
			{
				filename = filename.ToLower();
				foreach (string ext in secset.ImageFilters)
				{
					if (ext == null || ext.Length == 0) continue;
					if(filename.EndsWith(ext.ToLower()))
						return true;
				}
				return false;
			}
		    
			protected int GetUsedSpaceBarWidth()
			{
			int w = Convert.ToInt32(40*fs.GetDirectorySize(fs.VirtualRoot)/(secset.MaxImageFolderSize * 1024));
			if(w<1)
				w=1;
				
			if(w>40)
				w=40;
				
			return w;      
			}
			protected override string CheckUploadData(ref byte[] data)
			{            
		      
			if (fs.GetDirectorySize(fs.VirtualRoot) >= secset.MaxImageFolderSize * 1024)
				return "Image folder size exceeds the limit: "+ CuteEditor.Impl.FileStorage.FormatSize(secset.MaxImageFolderSize * 1024);

				System.Drawing.Image img;
				try
				{
					img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(data));
				}
				catch
				{
					return "Image is in the wrong format.";
				}

				//let base class to implement
				/*
		        
				if (data.Length >= secset.MaxImageSize * 1024)
				return "Image size exceeds "+CuteEditor.Impl.FileStorage.FormatSize(secset.MaxImageSize * 1024)+" limit: "+ CuteEditor.Impl.FileStorage.FormatSize(data.Length);


				if(secset.RestrictUploadedImageDimension)
				{
					if(secset.AutoResizeUploadedImages)
					{
						return null;//let base class implement the secset.AutoResizeUploadedImages
					}
					else
					{
						if ((img.Width > secset.MaxImageWidth) || ((img.Height > secset.MaxImageHeight)))
							return String.Format("Image dimension ({0} x {1} pixels) exceeding limits.", img.Width, img.Height);
					}	
				}
				*/
				
				return null;
			}
		</script>
		<script src="addvars.js"></script>
		<script>
		
			var obj=top.dialogArguments;

			var oControl=obj.img;
			var editor=obj.editor;
			
			var inp_width = document.getElementById("inp_width");
			var inp_height = document.getElementById("inp_height");
			var VSpace = document.getElementById("VSpace");
			var HSpace = document.getElementById("HSpace");
			var Border = document.getElementById("Border");
			var bordercolor = document.getElementById("bordercolor");
			var bordercolor_Preview = document.getElementById("bordercolor_Preview");
			var Align = document.getElementById("Align");
			var AlternateText = document.getElementById("AlternateText");
			var longDesc = document.getElementById("longDesc");		
			var TargetUrl = document.getElementById("TargetUrl");				

			if(!top.frameloaded)
			{
				top.frameloaded=true;	
				
				var src=oControl.src||'';
				if(obj.UseRelativeLinks)
					src= RemoveServerNamesFromUrl(src);
				TargetUrl.value=src;
				//	alert(oControl.getAttribute("src"));
				inp_width.value=oControl.width||'';
				inp_height.value=oControl.height||'';
				VSpace.value=oControl.vspace||'';
				HSpace.value=oControl.hspace||'';
				Border.value=oControl.border||'';
				bordercolor.value=oControl.style.borderColor||GetAttribute("bordercolor")||'';
				bordercolor.style.backgroundColor = bordercolor.value||''; 
				Align.value=oControl.align||'';
				AlternateText.value=oControl.alt||'';
				longDesc.value=oControl.longDesc||'';	
			}

			function GetAttribute(attrname)
			{
				var attr=oControl.getAttributeNode(attrname);
				if(attr&&attr.specified)
					return oControl[attr.nodeName];
				return "";
			}

			var sCheckFlag = "file";

			do_preview();
			
			function do_preview()
			{
				var imgname = TargetUrl.value;
				
				var foo = new Date(); 
				var now = foo.getTime();  
	
				if (imgname == "")
					imgname = "../images/1x1.gif";
				var sHTML = '<img id=preview_image onmousewheel="return Picture(this);"' 
				+ attr("src", imgname+"?" +now)
				+ attr("alt", AlternateText.value)
				+ attr("align", Align.value)
				+ ((inp_width.value)  ? attr("width" , inp_width.value)  : "")
				+ ((inp_height.value) ? attr("height", inp_height.value) : "")
				+ ((VSpace.value) ? attr("vspace", VSpace.value) : "")
				+ ((HSpace.value) ? attr("hspace", HSpace.value) : "")
				+ ((Border.value) ? attr("border", Border.value) : attr("border",0))				
				+ (((bordercolor.value)&&(Border.value > 0)) ? attr("style", "border-color="+bordercolor.value) : "")
				+ '/>';	
	
				divpreview.innerHTML = sHTML;
			}
			
			var count = 10
			function Picture(oImage)
			{	
				if (event.wheelDelta >= 120)
					count++;
				else if (event.wheelDelta <= -120)
					count--
				oImage.style.zoom = count + '0%'; 
				return false;
			}
			
			function RemoveServerNamesFromUrl(path)
			{	
				var serverurl = obj.BaseHref;			
				serverurl = serverurl.replace(/^(https?:\/\/[^\/]+)(.*)$/, '$1');
				serverre = new RegExp(serverurl);
				return path.replace(serverre, "");
			}
			
			function do_insert()
			{
				var img=oControl;
				img.src = TargetUrl.value;	
				img.width = inp_width.value;
				img.height = inp_height.value;
				img.vspace = VSpace.value;
				img.hspace = HSpace.value;
				img.border = Border.value;		
				try { 
					img.style.borderColor = bordercolor.value;
				} 
				catch(er) {
					alert("[[ValidColor]]");
					return false;
				} 
				img.align = Align.value;
				img.alt = AlternateText.value;
				img.longDesc = longDesc.value;
				
				if (TargetUrl.value == "") {
					alert("[[SelectImagetoInsert]]");
					return false;
				}
				if(img.width==0)
					img.removeAttribute('width');
				if(img.height==0)
					img.removeAttribute('height');
				if(img.longDesc=='')
					img.removeAttribute('longDesc');
				editor.InsertElement(img,obj.img);
				top.close();
			}
			
			function attr(name, value) 
			{
				if (!value || value == "") return "" ;
					return ' ' + name + '="' + value + '"' ;
			}
			
			function do_cancel()
			{
				top.close();
			}

			function IsDigit(){
				return ((event.keyCode >= 48) && (event.keyCode <= 57));
			}
			
			function Zoom_In()
			{
				if(divpreview.style.zoom!=0) 
					divpreview.style.zoom*=1.2; 
				else 
					divpreview.style.zoom=1.2;
			}

			function Zoom_Out()
			{
				if(divpreview.style.zoom!=0) 
					divpreview.style.zoom*=0.8; 
				else 
					divpreview.style.zoom=0.8;
			}
			
			function BestFit()
			{
				var img = GetPreviewedImage();
				if (!img) return;
				var height = 280;
				var width = 290;	
				divpreview.style.zoom=1/Math.max(img.width/width,img.height/height);
			}

			function Actualsize()
			{
				try
				{
					var img=new Image();
					img.src = document.getElementById("TargetUrl").value;
					if (img.width) 
						inp_width.value = img.width;
					if (img.height) 
						inp_height.value = img.height;
				}
				catch(er) {
				}
				divpreview.style.zoom=1;
				do_preview();
			}

			function GetPreviewedImage()
			{
				var imgs = divpreview.getElementsByTagName("IMG");
				if (imgs && imgs.length > 0)
				{
					return imgs.item(0);
				}
				else
				{
					return null;
				}
			}

			function toggleConstrains() 
			{
				var lockImage = document.getElementById('imgLock');
				var constrains = document.getElementById('constrain_prop');

				if(constrains.checked) 
				{
					lockImage.src = "../images/locked.gif";
					checkConstrains('width') 
				}
				else
				{
					lockImage.src = "../images/1x1.gif";
				}
			}

			var checkingConstrains=false;

			function checkConstrains(changed) 
			{
				//if onpropertychange fired by this function..
				if(checkingConstrains)return;
	
				checkingConstrains=true;
				try
				{
					var constrains = document.getElementById('constrain_prop');

					if(constrains.checked) 
					{
						var preview_image=document.getElementById("preview_image");
						if(preview_image)
						{
							//change the size ok , because do_preview() agian
				
							//move to no-zoomed element
				
							var div=document.createElement("DIV");
							div.style.cssText='position:absolute';
							document.body.appendChild(div);
				
							div.appendChild(preview_image);
				
							preview_image.removeAttribute('width');
							preview_image.removeAttribute('height');
							preview_image.style.width=''
							preview_image.style.height=''
				
							original_width=preview_image.offsetWidth;
							original_height=preview_image.offsetHeight;
				
							div.removeNode(true);
						}
						else
						{
							var original = new Image();
							original.src = document.getElementById("TargetUrl").value;
							original_width= original.width;
							original_height = original.height;
						}

						if(original_width > 0 && original_height > 0) 
						{
							width = inp_width.value;
							height = inp_height.value;
			
							if(changed == 'width')
							{
								if ( width.length == 0 || isNaN( width ) )
								{
									inp_width.value='';
									inp_height.value='';
								}
								else
								{
									height = parseInt(width*original_height/original_width);
									inp_height.value = height;
								}
							}

							if(changed == 'height')
							{
								if ( height.length == 0 || isNaN( height ) )
								{	
									inp_width.value='';
									inp_height.value='';
								}
								else
								{
									width = parseInt(height*original_width/original_height);
									inp_width.value = width;
								}
							}
						}
					}
		
					do_preview();
				}
				finally
				{
					checkingConstrains=false;
				}
			}
			function ImageEditor()
			{
				if (document.getElementById("TargetUrl").value == "") {
					alert("[[SelectImagetoEdit]]");
					return false;
				}				
				var img=new Image();
				img.src = document.getElementById("TargetUrl").value;
				var src = document.getElementById("TargetUrl").value;
				var p = "[[_CuteEditorResource_]]";
				var arr = showModalDialog("../ImageEditor/ImageEditor.aspx?<%= Request.ServerVariables["QUERY_STRING"] %>&f="+src+"&p="+p+"", img, "dialogWidth:676px;dialogHeight:500px;help:no;scroll:no;status:no;resizable:0;");
				
			//	window.location.href = window.location.href;
				document.getElementById("TargetUrl").value=src;
				do_preview();				
			}			
		</script>
	</body>
</HTML>
